﻿using DreamStore.WebShop.Models;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;

namespace DreamStore.WebShop.Drivers
{
    public class ProductDriver : ContentPartDriver<ProductPart>
    {
        protected override DriverResult Display(ProductPart part, string displayType, dynamic shapeHelper)
        {
            return Combined(
                ContentShape("Parts_Product_SummaryAdmin", () => shapeHelper.Parts_Product_SummaryAdmin(Price: part.Price, Sku: part.Sku)),
                ContentShape("Parts_Product", () => shapeHelper.Parts_Product(Price: part.Price, Sku: part.Sku)),
                ContentShape("Parts_Product_AddButton", () => shapeHelper.Parts_Product_AddButton(ProductId: part.Id)),
                ContentShape("Parts_Product_Image", () => shapeHelper.Parts_Product_Image())
                );
        }

        //GET
        protected override DriverResult Editor(ProductPart part, dynamic shapeHelper)
        {
            return ContentShape(
                    "Parts_Product_Edit",
                    () => shapeHelper.EditorTemplate(TemplateName: "Parts/Product", Model: part, Prefix: Prefix));
        }

        //POST
        protected override DriverResult Editor(ProductPart part, IUpdateModel updater, dynamic shapeHelper)
        {
            updater.TryUpdateModel(part, Prefix, null, null);
            return Editor(part, shapeHelper);
        }
    }
}